package com.mokio.service.impl;

import com.mokio.entity.Address;
import com.mokio.entity.AddressExample;
import com.mokio.mapper.AddressMapper;
import com.mokio.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: xiaomishop
 * @ClassName AddressServiceImpl
 * @description:
 * @author: mokio
 * @create: 2024−12-21 09:49
 * @Version 1.0
 **/
@Service
public class AddressServiceImpl implements AddressService {
    @Autowired
    private AddressMapper addressMapper;


    @Override
    public List<Address> findAddressByUid(Integer uid) {
        AddressExample example = new AddressExample();
        example.createCriteria().andUidEqualTo(uid);
        List<Address> addressList = addressMapper.selectByExample(example);
        return addressList;
    }

    @Override
    public void insertAddress(Address address) {
        addressMapper.insertSelective(address);
    }

    @Override
    public Integer findAddressIdByExample(Address address) {
        AddressExample example = new AddressExample();
        example.createCriteria().andUidEqualTo(address.getUid());
        List<Address> addresses = addressMapper.selectByExample(example);
        for (Address address1 : addresses) {
            if (address1.getCnee().equals(address.getCnee())&&address1.getPhone().equals(address.getPhone())&&address1.getAddress().equals(address.getAddress())) {
                return address1.getAddressid();
            }
        }
        return null;
    }
}
